﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BCL.Tool;
using BCL.WPFComponent.Base;
using System.IO;
using Newtonsoft.Json;
using Setup;
namespace WpfControlTool.Controls
{
    /// <summary>
    /// UCConfig.xaml 的交互逻辑
    /// </summary>
    public partial class UCAppConfig : BaseFunctionControl
    {
        public UCAppConfig()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            List<LanguageKeyValue> lang= LanguagePackage.GetLanguagePackages();
            if (lang != null && lang.Count > 0)
            {
                comboboxLang.ItemsSource =lang;
                comboboxLang.DisplayMemberPath = "Value";
                comboboxLang.SelectedIndex = 0;
            }
            comboboxLang.SelectionChanged += ComboboxLang_SelectionChanged;

            if (File.Exists("setup.xml"))
            {
                try
                {
                    InstallInfo info = JsonConvert.DeserializeObject<InstallInfo>(File.ReadAllText("setup.xml"));
                    textBlockVersion.Text = $"{info.DisplayName}({info.DisplayVersion})";
                }
                catch (Exception)
                {
                }

            }

        }
        private void ComboboxLang_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LanguageKeyValue languageKeyValue = comboboxLang.SelectedItem as LanguageKeyValue;
            LanguagePackage.SetLanguage(languageKeyValue);
            BCL.WPFComponent.UCMessageBox.Show("设置成功重启程序生效!");
        }

        public override void LanguageBinding()
        {
          
        }
    }
}
